import scrapy


class LianjiaSpider(scrapy.Spider):
    name = 'lianjia'
    allowed_domains = ['lianjia.com']
    start_urls = ['https://cd.lianjia.com/zufang/wenjiang/']

    def parse(self, response):

        home_url = response.xpath('//div[@class="content__list"]//a[@class="content__list--item--aside"]//@href').getall()
        for h_url in home_url:
            yield scrapy.Request("https://cd.lianjia.com/"+h_url, callback=self.home_parse)

    def home_parse(self,response):
        home_title = response.xpath('//div[@class="top_left"]/p/text()').get()
        home_pay = response.xpath('string(//div[@id = "aside"])').get()
        home_area = response.xpath('//div[@id="info"]/ul[1]/li[2]').get()
        home_water = response.xpath('//div[@id="info"]/ul[1]/li[12]').get()
        home_light = response.xpath('//div[@id="info"]/ul[1]/li[14]').get()
        home_time = response.xpath('//div[@id="info"]/ul[2]/li[2]').get()
        yield {
            "home_title": home_title,
            "home_pay": home_pay,
            "home_area": home_area,
            "home_water": home_water,
            "home_light": home_light,
            "home_time": home_time
        }
